home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr01 / halcn305.zip / GSDMOTV1.PAS < prev    next >
Pascal/Delphi Source File  |  1993-02-15  |  6KB  |  230 lines

  1. program GSDMOTV1;
  2. {------------------------------------------------------------------------------
  3.                               DBase File Display
  4.                              TurboVision Sample 1
  5.  
  6.        Copyright (c)  Richard F. Griffin
  7.  
  8.        28 January 1993
  9.  
  10.        102 Molded Stone Pl
  11.        Warner Robins, GA  31088
  12.  
  13.        -------------------------------------------------------------
  14.        This program demonstrates that the basic Griffin Solutions
  15.        routines will work in a TurboVision environment.  This demo
  16.        modifies one of the TP 6 TurboVision documentation programs
  17.        to use a dBase file.
  18.  
  19.        Procedure ReadFile loads the dBase records into an array for
  20.        display and then closes the file.
  21.  
  22.        Memory is at a premium in the IDE using TurboVision.  If you
  23.        get heap overflow errors or 'strange' things happen, if probably
  24.        means there is not enough memory to run in the IDE.  To regain
  25.        memory, you can compile to disk instead of memory.  Use the
  26.        MemAvail value in the Watch window to see how much memory is
  27.        available.
  28.  
  29. -------------------------------------------------------------------------------}
  30.  
  31.  
  32. uses
  33.    GSOBShel,
  34.    GSOB_Gen,
  35.    Objects, Drivers, Views, Menus, App;
  36.  
  37. const
  38.   MaxLines          = 100;
  39.   WinCount: Integer =   0;
  40.   cmFileOpen        = 100;
  41.   cmNewWin          = 101;
  42.  
  43. var
  44.   LineCount: Integer;
  45.   Lines: array[0..MaxLines - 1] of PString;
  46.    
  47. type
  48.   TMyApp = object(TApplication)
  49.     procedure HandleEvent(var Event: TEvent); virtual;
  50.     procedure InitMenuBar; virtual;
  51.     procedure InitStatusLine; virtual;
  52.     procedure NewWindow;
  53.   end;
  54.  
  55.   PInterior = ^TInterior;
  56.   TInterior = object(TScroller)
  57.     constructor Init(var Bounds: TRect; AHScrollBar,
  58.       AVScrollBar: PScrollBar);
  59.     procedure Draw; virtual;
  60.   end;
  61.  
  62.   PDemoWindow = ^TDemoWindow;
  63.   TDemoWindow = object(TWindow)
  64.     constructor Init(Bounds: TRect; WinTitle: String; WindowNo: Word);
  65.     procedure MakeInterior(Bounds: TRect);
  66.   end;
  67.  
  68. procedure ReadFile;
  69. var
  70.    s : string;
  71. begin
  72.    if not FileExist('DEMOTV1.DBF') then
  73.    begin
  74.       MakeTestData(3,'DEMOTV1', 40, false);
  75.       Select(1);
  76.       Use('DEMOTV1');
  77.       IndexOn('DEMOTV1','LASTNAME + FIRSTNAME');
  78.    end
  79.    else
  80.    begin
  81.       Select(1);
  82.       Use('DEMOTV1');
  83.       Index('DEMOTV1');
  84.    end;
  85.    GoTop;
  86.    LineCount := 0;
  87.    while not dEOF and (LineCount < MaxLines) do
  88.    begin
  89.       s := FieldGet('LASTNAME') + FieldGet('FIRSTNAME');
  90.       Lines[LineCount] := NewStr(S);
  91.       inc(LineCount);
  92.       Skip(1);
  93.    end;
  94.    CloseDataBases;                  {Close the dBase III file}
  95. end;
  96.  
  97. procedure DoneFile;
  98. var
  99.   I: Integer;
  100. begin
  101.   for I := 0 to LineCount - 1 do
  102.     if Lines[I] <> nil then DisposeStr(Lines[i]);
  103. end;
  104.  
  105. { TInterior }
  106. constructor TInterior.Init(var Bounds: TRect; AHScrollBar,
  107.   AVScrollBar: PScrollBar);
  108. begin
  109.   TScroller.Init(Bounds, AHScrollBar, AVScrollBar);
  110.   GrowMode := gfGrowHiX + gfGrowHiY;
  111.   Options := Options or ofFramed;
  112.   SetLimit(128, LineCount);
  113. end;
  114.  
  115. procedure TInterior.Draw;
  116. var
  117.   Color: Byte;
  118.   I, Y: Integer;
  119.   B: TDrawBuffer;
  120. begin
  121.   Color := GetColor(1);
  122.   for Y := 0 to Size.Y - 1 do
  123.   begin
  124.     MoveChar(B, ' ', Color, Size.X);
  125.     i := Delta.Y + Y;
  126.     if (I < LineCount) and (Lines[I] <> nil) then
  127.       MoveStr(B, Copy(Lines[I]^, Delta.X + 1, Size.X), Color);
  128.     WriteLine(0, Y, Size.X, 1, B);
  129.   end;
  130. end;
  131.  
  132. { TDemoWindow }
  133. constructor TDemoWindow.Init(Bounds: TRect; WinTitle: String;
  134.   WindowNo: Word);
  135. var
  136.   S: string[3];
  137. begin
  138.   Str(WindowNo, S);
  139.   TWindow.Init(Bounds, WinTitle + ' ' + S, wnNoNumber);
  140.   MakeInterior(Bounds);
  141. end;
  142.  
  143. procedure TDemoWindow.MakeInterior(Bounds: TRect);
  144. var
  145.   HScrollBar, VScrollBar: PScrollBar;
  146.   Interior: PInterior;
  147.   R: TRect;
  148. begin
  149.   VScrollBar := StandardScrollBar(sbVertical + sbHandleKeyboard);
  150.   HScrollBar := StandardScrollBar(sbHorizontal + sbHandleKeyboard);
  151.   GetExtent(Bounds);
  152.   Bounds.Grow(-1,-1);
  153.   Interior := New(PInterior, Init(Bounds, HScrollBar, VScrollBar));
  154.   Insert(Interior);
  155. end;
  156.  
  157. { TMyApp }
  158. procedure TMyApp.HandleEvent(var Event: TEvent);
  159. begin
  160.   TApplication.HandleEvent(Event);
  161.   if Event.What = evCommand then
  162.   begin
  163.     case Event.Command of
  164.       cmNewWin: NewWindow;
  165.     else
  166.       Exit;
  167.     end;
  168.     ClearEvent(Event);
  169.   end;
  170. end;
  171.  
  172. procedure TMyApp.InitMenuBar;
  173. var R: TRect;
  174. begin
  175.   GetExtent(R);
  176.   R.B.Y := R.A.Y + 1;
  177.   MenuBar := New(PMenuBar, Init(R, NewMenu(
  178.     NewSubMenu('~F~ile', hcNoContext, NewMenu(
  179.       NewItem('~O~pen', 'F3', kbF3, cmFileOpen, hcNoContext,
  180.       NewItem('~N~ew', 'F4', kbF4, cmNewWin, hcNoContext,
  181.       NewLine(
  182.       NewItem('E~x~it', 'Alt-X', kbAltX, cmQuit, hcNoContext,
  183.       nil))))),
  184.     NewSubMenu('~W~indow', hcNoContext, NewMenu(
  185.       NewItem('~N~ext', 'F6', kbF6, cmNext, hcNoContext,
  186.       NewItem('~Z~oom', 'F5', kbF5, cmZoom, hcNoContext,
  187.       nil))),
  188.     nil))
  189.   )));
  190. end;
  191.  
  192. procedure TMyApp.InitStatusLine;
  193. var R: TRect;
  194. begin
  195.   GetExtent(R);
  196.   R.A.Y := R.B.Y - 1;
  197.   StatusLine := New(PStatusLine, Init(R,
  198.     NewStatusDef(0, $FFFF,
  199.       NewStatusKey('', kbF10, cmMenu,
  200.       NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit,
  201.       NewStatusKey('~F4~ New', kbF4, cmNewWin,
  202.       NewStatusKey('~Alt-F3~ Close', kbAltF3, cmClose,
  203.       nil)))),
  204.     nil)
  205.   ));
  206. end;
  207.  
  208. procedure TMyApp.NewWindow;
  209. var
  210.   Window: PDemoWindow;
  211.   R: TRect;
  212. begin
  213.   Inc(WinCount);
  214.   R.Assign(0, 0, 50, 15);
  215.   R.Move(Random(29), Random(8));
  216.   Window := New(PDemoWindow, Init(R, 'Demo Window', WinCount));
  217.   DeskTop^.Insert(Window);
  218. end;
  219.  
  220. var
  221.   MyApp: TMyApp;
  222.  
  223. begin
  224.   ReadFile;
  225.   MyApp.Init;
  226.   MyApp.Run;
  227.   MyApp.Done;
  228.   DoneFile;
  229. end.
  230.